package org.ezplatform.component.fileview.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.thunisoft.ofd.operate.IPdfOperationAgent;
import com.thunisoft.ofd.operate.PdfOperation;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.ezplatform.component.attachment.entity.Attachment;
import org.ezplatform.component.attachment.service.AttachmentService;
import org.ezplatform.component.attachment.util.AttachUtils;
import org.ezplatform.component.fileview.dto.FileViewTempDto;
import org.ezplatform.component.fileview.util.DealServerIpUtil;
import org.ezplatform.component.fileview.util.FileViewCommonUtil;
import org.ezplatform.component.fileview.web.rest.FileTransformWebApiController;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.system.basic.util.ConfSettingUtils;
import org.ezplatform.util.Encodes;
import org.ezplatform.util.MD5Utils;
import org.ezplatform.util.StringUtils;
import org.ezplatform.util.GlobalConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.thunisoft.ofd.operate.IOfdOperationAgent;
import com.thunisoft.ofd.operate.OfdOperation;

@Service
public class ArteryPaperViewService{
	private static final Logger LOG = LoggerFactory.getLogger(FileTransformWebApiController.class);

	//基础参数设置 paper预览符类型
	private static String[] allowFileTypes = {".doc",".docx",".ppt",".pptx",".xls",".xlsx",".pdf",".jpg",".jpeg",".png",".bmp",".gif",".ofd",".wps",".html",".txt",".et",".ett",".tif",".tiff"};
	private static String[] keepWordFileTypes = {".doc",".docx",".ppt",".pptx",".xls",".xlsx",".wps"};
	private static String[] excelUrlTypes = {".xls",".xlsx",".et",".ett"};
	private static String pdfSuffix = ".pdf";

	@Autowired
	private AttachmentService attachmentService;
	
	@Autowired
	private FileViewTempDtoService fileViewTempDtoService;
	
	public String arteryPaperView(HttpServletRequest request, String fileId,String fileSourceType,String jwtToken,String filePw) {
		//1、基础参数设置
		
		//2、相关变量设置
		String convertUrl = "";//预览接口返回结果集：convertUr
		String encodeConvertUrl = "";//预览接口返回结果集：convertUrl中真实路径访问地址需要encode编码
		String previewHtmlUrl = "";//预览文件访问路径：在convertUrl中获取
		String fileDownloadUrl = "";//附件文件下载路径
		String fileExt = "";//文件后缀名
		String fileExtLower = "";//文件后缀名全部小写
		Date previewDate = null;//预览生成时间
		String previewUrl = "";//预览地址
		String fileName = "";
		boolean keepWordAnnotation = false;
		boolean isExpendDate = false; 
		boolean isShowPrintBut = false;//是否可以打印
		boolean isShowSuofangBut = false;//是否显示缩放
		boolean isShowDownLoadBut = false;//是否下载
		boolean isShowFooterBut = false;//是否加载水印
		boolean isAcceptTracks = false;//是否显示批注
		
		//3、获取ateryPaper参数设置
		String  servicePath= ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrl", "0");//获取arteryPaper服务地址(内网)
		String servicePathOut = ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrlOut", "0");//获取arteryPaper服务地址(外网)
		String sysImType = ConfSettingUtils.getConfSettingValue("fcButton", "0");//arteryPaper预览服务设置是否打印、缩放大小、下载、水印、批注
		if(StringUtils.isNotEmpty(sysImType)) {
			if(sysImType.contains("print")) {
				isShowPrintBut = true;
			}
			if(sysImType.contains("resizing")) {
				isShowSuofangBut = true;
			}
			if(sysImType.contains("download")) {
				isShowDownLoadBut = true;
			}
			if(sysImType.contains("showFooter")) {
				isShowFooterBut = true;
			}
			if(sysImType.contains("acceptTracks")) {
				isAcceptTracks = true;
			}
		}
		//453新增缩放比例 fitWidth（适应宽度） 0.75  1  1.25  1.75 2
		String zoom = GlobalConstant.getConfig("file.view.zoom");
		
		//4、获取附件相关数据：根据fileId获取附件相关数据；1、需要判断fileId来源（附件表、网盘）；2、返回文件相关数据
		Map<String,Object> fileParams = new HashMap<String,Object>();
		fileParams.put("fileId", fileId);
		fileParams.put("fileSourceType", fileSourceType);
		fileParams.put("jwtToken", jwtToken);
		FileViewTempDto dto = fileViewTempDtoService.getFileTempDtoInfo(fileParams);
		if(StringUtils.isBlank(dto.getFileId())) {
			String msg = "文件FileId:"+fileId+"不存在";
			return "{\"result\":-1,\"data\":\"\",\"message\":\""+msg+"\",\"type\":0}";
		}
		fileExt = dto.getFileExt();
		fileExtLower = fileExt.toLowerCase();
		previewDate = dto.getPreviewDate();
		previewUrl = dto.getPreviewUrl();
		fileDownloadUrl = dto.getFileDownloadUrl();
		fileName = dto.getFileName();

		fileName = fileName.replaceAll("“","").replaceAll("”","");
		
		//5、校验文件是否支持预览及调用ateryPaper预览服务
		//校验格式，只支持".doc",".docx",".ppt",".excel",".pdf",".jpg",".png",".ofd",".html"预览
		if(!Arrays.asList(allowFileTypes).contains(fileExtLower)){
			encodeConvertUrl = "{\"result\":-1,\"data\":\"\",\"message\":\"该格式暂不支持预览\",\"type\":0}";
			return encodeConvertUrl;
		}
		if(!Arrays.asList(keepWordFileTypes).contains(fileExtLower)){
			keepWordAnnotation = true;
		}
		
		Map<String,String> param = new HashMap<String,String>();

		try {
			//文件在paper预览缓存是否存在
			boolean paperIsExsitCache = false;
			//paper预览服务 需根据文件类型、预览地址判断文件类型是否需要读取缓存paper缓存接口校验
			//excel pdf ofd文件类型没有缓存 其他文件类型有缓存需判断是否有paper服务缓存
			//1、校验文件是否已预览 预览地址属于paper服务
			LOG.debug("previewUrl url previewUrl="+previewUrl);
			LOG.debug("previewUrl url fileExtLower="+fileExtLower);
			if(StringUtils.isNotEmpty(previewUrl) && (previewUrl.contains("/convert/convertExcelUrl") || previewUrl.contains("preview.html"))){
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower) || fileExtLower.equals(".pdf") || fileExtLower.equals(".ofd")){
					paperIsExsitCache = true;
				}else{
					String threadId = getFieldValue(previewUrl, "threadId");
					if(StringUtils.isEmpty(threadId)){
						threadId = getFieldValue(previewUrl, "fileId");
					}
					if(StringUtils.isNotEmpty(threadId)){
						LOG.error("pdf url="+servicePath+"/pdf/getPDFCacheStatus?threadId="+threadId);
						String result = this.sendViewFileGet(servicePath+"/pdf/getPDFCacheStatus?threadId="+threadId);
						LOG.error("pdf url result="+result);
						if(StringUtils.isNotEmpty(result)){
							JSONObject resultJson = JSONObject.parseObject(result);
							if(resultJson.getString("status").equals("1")){
								paperIsExsitCache = true;
							}
						}
						if(!paperIsExsitCache){
							LOG.error("ofd url="+servicePath+"/convert/getOfdCacheStatus?threadId="+threadId);
							String	result1 = this.sendViewFileGet(servicePath+"/convert/getOfdCacheStatus?threadId="+threadId);
							LOG.error("ofd url result="+result1);
							if(StringUtils.isNotEmpty(result1)){
								JSONObject resultJson1 = JSONObject.parseObject(result1);
								if(resultJson1.getString("status").equals("1")){
									paperIsExsitCache = true;
								}
							}
						}
					}
				}
			}
			
			if(StringUtils.isBlank(previewUrl) || (!previewUrl.contains("preview.html") && !previewUrl.contains("/convert/convertExcelUrl")) || (Arrays.asList(excelUrlTypes).contains(fileExtLower) && previewUrl.contains("result.ofd")) || previewDate == null || !paperIsExsitCache) {
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					String threadId = UUID.randomUUID().toString().replace("-", "");
					previewUrl = "/convert/convertExcelUrl?password="+filePw+"&threadId="+threadId+"&fileName="+fileName+"&fileurl="+URLEncoder.encode( fileDownloadUrl, "UTF-8" );;
					
					dto.setPreviewUrl(previewUrl);
					dto.setPreviewDate(new Date());
					this.fileViewTempDtoService.saveFileInfo(dto);
					previewUrl = servicePath + previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					param.put("fileName", fileName);
					param.put("fileurl", fileDownloadUrl);
					param.put("password",filePw);
					if(fileExtLower.equals(".ofd") || fileExtLower.equals(".pdf")) {
						previewUrl = servicePath;
						previewUrl +="/preview.html?";
						previewUrl +="fileId="+MD5Utils.hash(fileId+System.currentTimeMillis());
						String ofdDoloadUrl = fileDownloadUrl;
						if(fileExtLower.equals(".pdf")) {
							previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
							previewUrl +="&docType=pdf";
						}else {
							previewUrl +="&ofdFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
						}
						dto.setPreviewUrl(previewUrl);
						dto.setPreviewDate(new Date());
						dto = this.fileViewTempDtoService.saveFileInfo(dto);
						
						previewUrl +="&showToolbarPencil="+false;
						previewUrl +="&showToolbarAnnot="+false;
						previewUrl +="&showToolbarSelect="+false;
						previewUrl +="&showToolbarPrint="+isShowPrintBut;
						previewUrl +="&showToolbarPage="+false;
						previewUrl +="&showToolbarZoom="+isShowSuofangBut;
						previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
						previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
						previewUrl +="&canCopyText="+false;
						if(StringUtils.isNotEmpty(zoom)) {
							previewUrl += "&scaleRatio=" + zoom;
						}
						previewUrl = "[\""+previewUrl+"\"]";
						previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
						String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
						encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
					
					}else {
//						String isSm = GlobalConstant.getConfig("app.flexbase.fileview.issm");
						//if(StringUtils.isNotEmpty(isSm) && isSm.equals("true")) {//转成pdf
							convertUrl = sendViewFilePost(servicePath+"/pdf/convert2PDF", param,keepWordAnnotation);
							JSONObject urlJson = JSONObject.parseObject(convertUrl);
							if("success".equals(urlJson.get("status"))){
								previewUrl = servicePath;
								previewUrl +="/preview.html?";
								previewUrl +="fileId="+urlJson.get("threadId");
								String ofdDoloadUrl = (String) urlJson.get("pdfDoloadUrl");
								previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
								previewUrl +="&docType=pdf";
								dto.setPreviewUrl(previewUrl);
								dto.setPreviewDate(new Date());
								dto = this.fileViewTempDtoService.saveFileInfo(dto);
								
								previewUrl +="&showToolbarPencil="+false;
								previewUrl +="&showToolbarAnnot="+false;
								previewUrl +="&showToolbarSelect="+false;
								previewUrl +="&showToolbarPrint="+isShowPrintBut;
								previewUrl +="&showToolbarPage="+false;
								previewUrl +="&showToolbarZoom="+isShowSuofangBut;
								previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
								previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
								previewUrl +="&canCopyText="+false;
								if(StringUtils.isNotEmpty(zoom)) {
									previewUrl += "&scaleRatio=" + zoom;
								}
								previewUrl = "[\""+previewUrl+"\"]";
								previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
								String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
								encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
							}else{
								return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换失败:"+urlJson.getString("message")+"\",\"type\":0}";
							}
//						}else {
//							
//						}
					}
				}
				
			}else {
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					previewUrl = servicePath+previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					previewUrl = previewUrl.replace("/mobilepreview.html", "/preview.html");
					previewUrl +="&showToolbarPencil=false";
					previewUrl +="&showToolbarAnnot=false";

					previewUrl +="&showToolbarSelect=false";
					previewUrl +="&showToolbarPrint="+isShowPrintBut;
					previewUrl +="&showToolbarPage=false";
					previewUrl +="&showToolbarZoom="+isShowSuofangBut;
					previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
					previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
					previewUrl +="&canCopyText="+false;
					if(StringUtils.isNotEmpty(zoom)) {
						previewUrl += "&scaleRatio=" + zoom;
					}
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}
			}
		} catch (HttpHostConnectException e) {
			LOG.error("paper预览服务错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
		} catch (ParseException e) {
			LOG.error("paper预览转换错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		} catch (IOException e) {
			LOG.error("paper预览转换错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		}
		return encodeConvertUrl;
	}
	public String arteryPaperView_dobulescreen(HttpServletRequest request, String fileId,String fileSourceType,
											   String jwtToken,String filePw,String isAiRead) {
		//1、基础参数设置

		//2、相关变量设置
		String convertUrl = "";
		String encodeConvertUrl = "";//paper预览接口返回结果集：convertUrl中真实路径访问地址需要encode编码
		String previewHtmlUrl = "";//paper预览文件访问路径：在convertUrl中获取
		String fileDownloadUrl = "";//附件文件下载路径
		String fileExt = "";//文件后缀名
		String fileExtLower = "";//文件后缀名全部小写
		Date previewDate = null;//预览生成时间
		String previewUrl = "";//预览地址
		String fileName = "";
		boolean keepWordAnnotation = false;
		boolean isExpendDate = false;
		boolean isShowPrintBut = false;//是否可以打印
		boolean isShowSuofangBut = false;//是否显示缩放
		boolean isShowDownLoadBut = false;//是否下载
		boolean isShowFooterBut = false;//是否加载水印
		boolean isAcceptTracks = false;//是否显示批注

		//3、获取ateryPaper参数设置
		String  servicePath= ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrl", "0");//获取永中服务地址(内网)
		String servicePathOut = ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrlOut", "0");//获取永中服务地址(外网)
		String sysImType = ConfSettingUtils.getConfSettingValue("fcButton", "0");//ateryPaper预览服务设置是否打印、缩放大小、下载、水印、批注
		if(StringUtils.isNotEmpty(sysImType)) {
			if(sysImType.contains("print")) {
				isShowPrintBut = true;
			}
			if(sysImType.contains("resizing")) {
				isShowSuofangBut = true;
			}
			if(sysImType.contains("download")) {
				isShowDownLoadBut = true;
			}
			if(sysImType.contains("showFooter")) {
				isShowFooterBut = true;
			}
			if(sysImType.contains("acceptTracks")) {
				isAcceptTracks = true;
			}
		}
		//4、获取附件相关数据：根据fileId获取附件相关数据；1、需要判断fileId来源（附件表、网盘）；2、返回文件相关数据
		Map<String,Object> fileParams = new HashMap<String,Object>();
		fileParams.put("fileId", fileId);
		fileParams.put("fileSourceType", fileSourceType);
		fileParams.put("jwtToken", jwtToken);
		FileViewTempDto dto = fileViewTempDtoService.getFileTempDtoInfo(fileParams);
		if(StringUtils.isBlank(dto.getFileId())) {
			String msg = "文件FileId:"+fileId+"不存在";
			return "{\"result\":-1,\"data\":\"\",\"message\":\""+msg+"\",\"type\":0}";
		}
		fileExt = dto.getFileExt();
		fileExtLower = fileExt.toLowerCase();
		previewDate = dto.getPreviewDate();
		previewUrl = dto.getPreviewUrl();
		fileDownloadUrl = dto.getFileDownloadUrl();
		fileName = dto.getFileName();

		//5、校验文件是否支持预览及调用ateryPaper预览服务
		//校验格式，只支持".doc",".docx",".ppt",".excel",".pdf",".jpg",".png",".ofd",".html"预览
		if(!Arrays.asList(allowFileTypes).contains(fileExtLower)){
			encodeConvertUrl = "{\"result\":-1,\"data\":\"\",\"message\":\"该格式暂不支持预览\",\"type\":0}";
			return encodeConvertUrl;
		}
		if(!Arrays.asList(keepWordFileTypes).contains(fileExtLower)){
			keepWordAnnotation = true;
		}

		Map<String,String> param = new HashMap<String,String>();
		try {
			//文件在paper预览缓存是否存在
			boolean paperIsExsitCache = false;
			//paper预览服务 需根据文件类型、预览地址判断文件类型是否需要读取缓存paper缓存接口校验
			//excel pdf ofd文件类型没有缓存 其他文件类型有缓存需判断是否有paper服务缓存
			//1、校验文件是否已预览 预览地址属于paper服务
			LOG.error("previewUrl url previewUrl="+previewUrl);
			LOG.error("previewUrl url fileExtLower="+fileExtLower);
			if(StringUtils.isNotEmpty(previewUrl) && (previewUrl.contains("/convert/convertExcelUrl") || previewUrl.contains("preview.html"))){
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower) || fileExtLower.equals(".pdf") || fileExtLower.equals(".ofd")){
					paperIsExsitCache = true;
				}else{
					String threadId = getFieldValue(previewUrl, "threadId");
					if(StringUtils.isEmpty(threadId)){
						threadId = getFieldValue(previewUrl, "fileId");
					}
					if(StringUtils.isNotEmpty(threadId)){
						LOG.error("pdf url="+servicePath+"/pdf/getPDFCacheStatus?threadId="+threadId);
						String result = this.sendViewFileGet(servicePath+"/pdf/getPDFCacheStatus?threadId="+threadId);
						LOG.error("pdf url result="+result);
						if(StringUtils.isNotEmpty(result)){
							JSONObject resultJson = JSONObject.parseObject(result);
							if(resultJson.getString("status").equals("1")){
								paperIsExsitCache = true;
							}
						}
						if(!paperIsExsitCache){
							LOG.error("ofd url="+servicePath+"/convert/getOfdCacheStatus?threadId="+threadId);
							String	result1 = this.sendViewFileGet(servicePath+"/convert/getOfdCacheStatus?threadId="+threadId);
							LOG.error("ofd url result="+result1);
							if(StringUtils.isNotEmpty(result1)){
								JSONObject resultJson1 = JSONObject.parseObject(result1);
								if(resultJson1.getString("status").equals("1")){
									paperIsExsitCache = true;
								}
							}
						}
					}
				}
			}

			if(StringUtils.isBlank(previewUrl) || (!previewUrl.contains("preview.html") && !previewUrl.contains("/convert/convertExcelUrl")) || (Arrays.asList(excelUrlTypes).contains(fileExtLower) && previewUrl.contains("result.ofd")) || previewDate == null || !paperIsExsitCache) {
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					String threadId = UUID.randomUUID().toString().replace("-", "");
					previewUrl = "/convert/convertExcelUrl?password="+filePw+"&threadId="+threadId+"&fileName="+fileName+"&fileurl="+URLEncoder.encode( fileDownloadUrl, "UTF-8" );;

					dto.setPreviewUrl(previewUrl);
					dto.setPreviewDate(new Date());
					this.fileViewTempDtoService.saveFileInfo(dto);
					previewUrl = servicePath + previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					param.put("fileName", fileName);
					param.put("fileurl", fileDownloadUrl);
					param.put("password",filePw);
					if(fileExtLower.equals(".ofd") || fileExtLower.equals(".pdf")) {
						previewUrl = servicePath;
						previewUrl +="/preview.html?";
						previewUrl +="fileId="+MD5Utils.hash(fileId+System.currentTimeMillis());
						String ofdDoloadUrl = fileDownloadUrl;
						if(fileExtLower.equals(".pdf")) {
							previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
							previewUrl +="&docType=pdf&scaleRatio=fitWidth";
						}else {
							previewUrl +="&ofdFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
						}
						dto.setPreviewUrl(previewUrl);
						dto.setPreviewDate(new Date());
						dto = this.fileViewTempDtoService.saveFileInfo(dto);

						previewUrl +="&showToolbarPencil="+false;
						previewUrl +="&showToolbarAnnot="+false;
						previewUrl +="&showToolbarSelect="+false;
						previewUrl +="&showToolbarPrint="+isShowPrintBut;
						previewUrl +="&showToolbarPage="+false;
						previewUrl +="&showToolbarZoom="+isShowSuofangBut;
						previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
						previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
						LOG.error("--------isAiRead----------"+isAiRead);
						if("1".equals(isAiRead)){
							previewUrl +="&canCopyText="+true;
						}else {
							previewUrl +="&canCopyText="+false;
						}
						previewUrl = "[\""+previewUrl+"\"]";
						previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
						String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
						encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";

					}else {
//						String isSm = GlobalConstant.getConfig("app.flexbase.fileview.issm");
						//if(StringUtils.isNotEmpty(isSm) && isSm.equals("true")) {//转成pdf
						convertUrl = sendViewFilePost(servicePath+"/pdf/convert2PDF", param,keepWordAnnotation);
						JSONObject urlJson = JSONObject.parseObject(convertUrl);
						if("success".equals(urlJson.get("status"))){
							previewUrl = servicePath;
							previewUrl +="/preview.html?";
							previewUrl +="fileId="+urlJson.get("threadId");
							String ofdDoloadUrl = (String) urlJson.get("pdfDoloadUrl");
							previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
							previewUrl +="&docType=pdf";
							dto.setPreviewUrl(previewUrl);
							dto.setPreviewDate(new Date());
							dto = this.fileViewTempDtoService.saveFileInfo(dto);

							previewUrl +="&showToolbarPencil="+false;
							previewUrl +="&showToolbarAnnot="+false;
							previewUrl +="&showToolbarSelect="+false;
							previewUrl +="&showToolbarPrint="+isShowPrintBut;
							previewUrl +="&showToolbarPage="+false;
							previewUrl +="&showToolbarZoom="+isShowSuofangBut;
							previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
							previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
							previewUrl +="&canCopyText="+false;
							previewUrl = "[\""+previewUrl+"\"]";
							previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
							String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
							encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
						}else{
							return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换失败:"+urlJson.getString("message")+"\",\"type\":0}";
						}
//						}else {
//
//						}
					}
				}

			}else {
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					previewUrl = servicePath+previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					previewUrl = previewUrl.replace("/mobilepreview.html", "/preview.html");
					previewUrl +="&showToolbarPencil=false";
					previewUrl +="&showToolbarAnnot=false";

					previewUrl +="&showToolbarSelect=false";
					previewUrl +="&showToolbarPrint="+isShowPrintBut;
					previewUrl +="&showToolbarPage=false";
					previewUrl +="&showToolbarZoom="+isShowSuofangBut;
					previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
					previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
					previewUrl +="&canCopyText="+false;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrl(request, previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}
			}
		} catch (HttpHostConnectException e) {
			LOG.error("paper预览服务错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
		} catch (ParseException e) {
			LOG.error("paper预览转换错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		} catch (IOException e) {
			LOG.error("paper预览转换错误：", e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		}
		return encodeConvertUrl;
	}
	public String arteryPaperMobileView(HttpServletRequest request, String fileId,String fileSourceType,String jwtToken,String filePw) {
		LOG.error("arteryPaperMobileView...");
		//1、基础参数设置

		//2、相关变量设置
		String convertUrl = "";
		String encodeConvertUrl = "";//paper预览接口返回结果集：convertUrl中真实路径访问地址需要encode编码
		String previewHtmlUrl = "";//paper预览文件访问路径：在convertUrl中获取
		String fileDownloadUrl = "";//附件文件下载路径
		String fileExt = "";//文件后缀名
		String fileExtLower = "";//文件后缀名全部小写
		Date previewDate = null;//预览生成时间
		String previewUrl = "";//预览地址
		String fileName = "";
		boolean keepWordAnnotation = false;
		boolean isExpendDate = false; 
		boolean isShowPrintBut = false;//是否可以打印
		boolean isShowSuofangBut = false;//是否显示缩放
		boolean isShowDownLoadBut = false;//是否下载
		boolean isShowFooterBut = false;//是否加载水印
		boolean isAcceptTracks = false;//是否显示批注
		
		//3、获取ateryPaper参数设置
		String  servicePath= ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrl", "0");//获取永中服务地址(内网)
		String servicePathOut = ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrlOut", "0");//获取永中服务地址(外网)
		String sysImType = ConfSettingUtils.getConfSettingValue("fcButton", "0");//ateryPaper预览服务设置是否打印、缩放大小、下载、水印、批注
		if(StringUtils.isNotEmpty(sysImType)) {
			if(sysImType.contains("print")) {
				isShowPrintBut = true;
			}
			if(sysImType.contains("resizing")) {
				isShowSuofangBut = true;
			}
			if(sysImType.contains("download")) {
				isShowDownLoadBut = true;
			}
			if(sysImType.contains("showFooter")) {
				isShowFooterBut = true;
			}
			if(sysImType.contains("acceptTracks")) {
				isAcceptTracks = true;
			}
		}
		//453新增缩放比例 fitWidth（适应宽度） 0.75  1  1.25  1.75 2
		String zoom = GlobalConstant.getConfig("file.view.zoom");
		//4、获取附件相关数据：根据fileId获取附件相关数据；1、需要判断fileId来源（附件表、网盘）；2、返回文件相关数据
		Map<String,Object> fileParams = new HashMap<String,Object>();
		fileParams.put("fileId", fileId);
		fileParams.put("fileSourceType", fileSourceType);
		fileParams.put("jwtToken", jwtToken);
		FileViewTempDto dto = fileViewTempDtoService.getFileTempDtoInfo(fileParams);
		if(StringUtils.isBlank(dto.getFileId())) {
			String msg = "文件FileId:"+fileId+"不存在";
			return "{\"result\":-1,\"data\":\"\",\"message\":\""+msg+"\",\"type\":0}";
		}
		fileExt = dto.getFileExt();
		fileExtLower = fileExt.toLowerCase();
		previewDate = dto.getPreviewDate();
		previewUrl = dto.getPreviewUrl();
		fileDownloadUrl = dto.getFileDownloadUrl();
		fileName = dto.getFileName();
		
		//5、校验文件是否支持预览及调用ateryPaper预览服务
		//校验格式，只支持".doc",".docx",".ppt",".excel",".pdf",".jpg",".png",".ofd",".html"预览
		if(!Arrays.asList(allowFileTypes).contains(fileExtLower)){
			encodeConvertUrl = "{\"result\":-1,\"data\":\"\",\"message\":\"该格式暂不支持预览\",\"type\":0}";
			return encodeConvertUrl;
		}
		if(!Arrays.asList(keepWordFileTypes).contains(fileExtLower)){
			keepWordAnnotation = true;
		}
		Map<String,String> param = new HashMap<String,String>();

		try {
			//文件在paper预览缓存是否存在
			boolean paperIsExsitCache = false;
			//paper预览服务 需根据文件类型、预览地址判断文件类型是否需要读取缓存paper缓存接口校验
			//excel pdf ofd文件类型没有缓存 其他文件类型有缓存需判断是否有paper服务缓存
			//1、校验文件是否已预览 预览地址属于paper服务
			if(StringUtils.isNotEmpty(previewUrl) && (previewUrl.contains("/convert/convertExcelUrl") || previewUrl.contains("preview.html"))){
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower) || fileExtLower.equals(".pdf") || fileExtLower.equals(".ofd")){
					paperIsExsitCache = true;
				}else{
					String threadId = getFieldValue(previewUrl, "threadId");
					if(StringUtils.isEmpty(threadId)){
						threadId = getFieldValue(previewUrl, "fileId");
					}
					if(StringUtils.isNotEmpty(threadId)){
						String result = this.sendViewFileGet(servicePath+"/pdf/getPDFCacheStatus?threadId="+threadId);
						if(StringUtils.isNotEmpty(result)){
							JSONObject resultJson = JSONObject.parseObject(result);
							if(resultJson.getString("status").equals("1")){
								paperIsExsitCache = true;
							}
						}
						if(!paperIsExsitCache){
						     String	result1 = this.sendViewFileGet(servicePath+"/convert/getOfdCacheStatus?threadId="+threadId);
							if(StringUtils.isNotEmpty(result1)){
								JSONObject resultJson1 = JSONObject.parseObject(result1);
								if(resultJson1.getString("status").equals("1")){
									paperIsExsitCache = true;
								}
							}
						}
					}
				}
			}

			if(StringUtils.isBlank(previewUrl) || (!previewUrl.contains("preview.html") && !previewUrl.contains("/convert/convertExcelUrl")) || (Arrays.asList(excelUrlTypes).contains(fileExtLower) && previewUrl.contains("result.ofd")) || previewDate == null || !paperIsExsitCache) {
				//fileName = "aa.xlsx";
				//fileDownloadUrl = "http://61.190.4.70:50475/flexbase/attachment/download?fid=40288031751aacc901751abcdf84016d&chksum=eb202d98e0f43af6ec5510039a77f617&displayname=02%E3%80%90%E9%9D%9E%E5%AF%86%E3%80%911%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%8633333%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86333332.xlsx&token=eyJhbGciOiJIUzUxMiIsInppcCI6IkRFRiJ9.eNqMj0FOxDAMRa-Csp5ITtI0aXdIbFiAWCDB1kncKjA0VdMygxBH4BCsOQEHYsEtSMscgJ39__O3_coe5shaJhoy2FjHlTSWV75UGILglRBSW5JW68B2LC-uwBVIa0EJo6SHWgX4q8g7RABnChhzLmC3p6PDTHxOjzTwTNMzTauLM2tFDdJIBcbuGB3Hk6CbTfBpGi9DiYCC--Ean6g0Px9f3--fRdmnPg63L-Mqjof1sqWEn3uflqFEs_uIQ39HsRhdnPJ8cwhXKcQuUrjAeZ2SIIGD5aDPhG1F0wKcUra1_3gxTf2G6lqK4MkToq4kKtdVtXUqqC64ygbN3n4BAAD__w.EJX5LPHjqCSXoBFGgdZwdiYsEhVpmgXZY7E-6JssGjdYGQk4RKaM7711K6xrMOyI4gaVx9RbEKkJzZp-72vO4Q";
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					String threadId = UUID.randomUUID().toString().replace("-", "");
					previewUrl = "/convert/convertExcelUrl?password="+filePw+"&threadId="+threadId+"&fileName="+fileName+"&fileurl="+URLEncoder.encode( fileDownloadUrl, "UTF-8" );;
					
					dto.setPreviewUrl(previewUrl);
					dto.setPreviewDate(new Date());
					this.fileViewTempDtoService.saveFileInfo(dto);
					
					previewUrl = servicePath+previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrlByMobile(previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					param.put("fileName", fileName);
					param.put("fileurl", fileDownloadUrl);
					param.put("password",filePw);
					if(fileExtLower.equals(".ofd") || fileExtLower.equals(".pdf")) {
						previewUrl = servicePath;
						previewUrl +="/mobilepreview.html?";
						previewUrl +="fileId="+MD5Utils.hash(fileId+System.currentTimeMillis());
						String ofdDoloadUrl = fileDownloadUrl;
						if(fileExtLower.equals(".pdf")) {
							previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
							previewUrl +="&docType=pdf";
						}else {
							previewUrl +="&ofdFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
						}
						dto.setPreviewUrl(previewUrl);
						dto.setPreviewDate(new Date());
						dto = this.fileViewTempDtoService.saveFileInfo(dto);
						
						previewUrl +="&showToolbarPencil="+false;
						previewUrl +="&showToolbarAnnot="+false;
						previewUrl +="&showToolbarSelect="+false;
						previewUrl +="&showToolbarPrint="+isShowPrintBut;
						previewUrl +="&showToolbarPage="+false;
						previewUrl +="&showToolbarZoom="+isShowSuofangBut;
						previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
						previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
						previewUrl +="&canCopyText="+false;
						if(StringUtils.isNotEmpty(zoom)) {
							previewUrl += "&scaleRatio=" + zoom;
						}
						previewUrl = "[\""+previewUrl+"\"]";
						previewUrl = DealServerIpUtil.getFileViewWebUrlByMobile(previewUrl, servicePath, servicePathOut);
						String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
						encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
					
					}else {
//						String isSm = GlobalConstant.getConfig("app.flexbase.fileview.issm");
						//if(StringUtils.isNotEmpty(isSm) && isSm.equals("true")) {//转成pdf
							convertUrl = sendViewFilePost(servicePath+"/pdf/convert2PDF", param,keepWordAnnotation);
							JSONObject urlJson = JSONObject.parseObject(convertUrl);
							if("success".equals(urlJson.get("status"))){
								previewUrl = servicePath;
								previewUrl +="/mobilepreview.html?";
								previewUrl +="fileId="+urlJson.get("threadId");
								String ofdDoloadUrl = (String) urlJson.get("pdfDoloadUrl");
								previewUrl +="&pdfFile="+URLEncoder.encode(ofdDoloadUrl, "UTF-8");
								previewUrl +="&docType=pdf";
								dto.setPreviewUrl(previewUrl);
								dto.setPreviewDate(new Date());
								dto = this.fileViewTempDtoService.saveFileInfo(dto);
								
								previewUrl +="&showToolbarPencil="+false;
								previewUrl +="&showToolbarAnnot="+false;
								previewUrl +="&showToolbarSelect="+false;
								previewUrl +="&showToolbarPrint="+isShowPrintBut;
								previewUrl +="&showToolbarPage="+false;
								previewUrl +="&showToolbarZoom="+isShowSuofangBut;
								previewUrl +="&showToolbarZoomButton="+isShowSuofangBut;
								previewUrl +="&showToolbarDownload="+isShowDownLoadBut;
								previewUrl +="&canCopyText="+false;
								if(StringUtils.isNotEmpty(zoom)) {
									previewUrl += "&scaleRatio=" + zoom;
								}
								previewUrl = "[\""+previewUrl+"\"]";
								previewUrl = DealServerIpUtil.getFileViewWebUrlByMobile(previewUrl, servicePath, servicePathOut);
								String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
								encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
							}else{
								return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换失败\",\"type\":0}";
							}
//						}else {
//							
//						}
					}
				}
			}else {
				if(Arrays.asList(excelUrlTypes).contains(fileExtLower)){//paper的excel需单独处理
					previewUrl = servicePath+previewUrl;
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrlByMobile(previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}else {
					previewUrl = previewUrl.replace("/preview.html", "/mobilepreview.html");
					if(isShowSuofangBut) {
						previewUrl +="&showMobileToolbar=true";
						previewUrl +="&showMobileToolbarPage=false";
						previewUrl +="&showMobileToolbarDownload=false";
					}else {
						previewUrl +="&showMobileToolbar=false";
					}

					previewUrl +="&canCopyText="+false;
					if(StringUtils.isNotEmpty(zoom)) {
						previewUrl += "&scaleRatio=" + zoom;
					}
					previewUrl = "[\""+previewUrl+"\"]";
					previewUrl = DealServerIpUtil.getFileViewWebUrlByMobile(previewUrl, servicePath, servicePathOut);
					String encodeUrl = "\""+Encodes.encodeBase64(previewUrl)+"\"";
					encodeConvertUrl = "{\"result\":0,\"data\":"+encodeUrl+",\"message\":\"转换成功\",\"type\":1}";
				}
			}
		} catch (HttpHostConnectException e) {
			LOG.error(e.getMessage(),e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
		} catch (ParseException e) {
			LOG.error(e.getMessage(),e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		} catch (IOException e) {
			LOG.error(e.getMessage(),e);
			return "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
		}
		return encodeConvertUrl;
	}
	
	
	/**
	 * 从url中获取ip和端口号
	 * @param uri
	 * @return
	 */
	public static URI getIP(URI uri) {
	    URI effectiveURI = null;
	    try {
	        effectiveURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
	    } catch (Throwable var4) {
	        effectiveURI = null;
	    }
	    return effectiveURI;
	}
	
	//推荐用法
	public static String sendPost(String url, Map<String,String> param) throws HttpHostConnectException,IOException,ParseException{
		String result = "";
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		String fullurl = "";
		//请求参数
		for(String key:param.keySet()){
			list.add(new BasicNameValuePair(key, param.get(key)));
		}
		try{
			fullurl = EntityUtils.toString(new UrlEncodedFormEntity(list,Consts.UTF_8));
		}catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}
		HttpPost httppost = new HttpPost(url+"?"+fullurl);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		try{
			CloseableHttpResponse response = httpClient.execute(httppost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				result = EntityUtils.toString(entity);
			}else{
				result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
			}
		}catch (HttpHostConnectException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}finally{
			httppost.releaseConnection();
		}
		return result;

	}
	
	//推荐用法
	public static String sendViewFilePost(String url, Map<String,String> param, boolean keepWordAnnotation) throws HttpHostConnectException,IOException,ParseException{
		String result = "";
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		String fullurl = "";
		//请求参数
		for(String key:param.keySet()){
			list.add(new BasicNameValuePair(key, param.get(key)));
		}
		try{
			fullurl = EntityUtils.toString(new UrlEncodedFormEntity(list,Consts.UTF_8));
		}catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}
		LOG.debug("PAPER URL="+url+"?"+fullurl+"&keepWordAnnotation="+keepWordAnnotation);
		HttpPost httppost = new HttpPost(url+"?"+fullurl+"&keepWordAnnotation="+keepWordAnnotation);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		try{
			CloseableHttpResponse response = httpClient.execute(httppost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				result = EntityUtils.toString(entity);
			}else{
				result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
			}
		}catch (HttpHostConnectException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}finally{
			httppost.releaseConnection();
		}
		return result;
		
	}
	
	//推荐用法
	public static String sendPostTranOFD(String url, Map<String,String> param,String keepAnno) throws HttpHostConnectException,IOException,ParseException{
		String result = "";
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		String fullurl = "";
		//请求参数
		for(String key:param.keySet()){
			list.add(new BasicNameValuePair(key, param.get(key)));
		}
		try{
			fullurl = EntityUtils.toString(new UrlEncodedFormEntity(list,Consts.UTF_8));
			if("1".equals(keepAnno)) {
				fullurl += "&keepWordAnnotation=true";
			}
		}catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}
		HttpPost httppost = new HttpPost(url+"?"+fullurl);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		try{
			CloseableHttpResponse response = httpClient.execute(httppost);
			if(response.getStatusLine().getStatusCode() == 200){
				HttpEntity entity = response.getEntity();
				result = EntityUtils.toString(entity);
			}else{
				result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换异常\",\"type\":0}";
			}
		}catch (HttpHostConnectException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}finally{
			httppost.releaseConnection();
		}
		return result;

	}

	/**
	 * 调用arterypaper服务生成ofd文件
	 * @param request
	 * @param fileName
	 * @param fileUrl
	 * @return
	 */
	public OperationResult arteryPaperConvert(HttpServletRequest request,String fileName,String fileUrl,
			String fileId,String fileSuffix,String keepAnno,String moduleCode, String ofdFileDisplayName,
			String fileExt,String fileSourceType,String jwtToken,String isUseOldFielName) {
		OperationResult result = null;
		try {
			//从后台设置中获取服务地址
			String servicePath = ConfSettingUtils.getConfSettingValue("sysCmpConversionPath", "0");
			//String servicePath = "http://114.255.140.98:5223/arterypaper/convert/convert2OFD";
			String convertUrl = "";
			String fileExtLower = ".html";
			String[] allowFileTypesConvert = {".doc",".docx",".ppt",".pptx",".xls",".xlsx",".pdf",".jpg",".png",".ofd",".wps",".html",".txt",".ett",".et",".dps",".uos",".eis",".xpx",".jpeg",".gif",".bmp",".tif",".tiff",".rtf"};
			String ofdDoloadUrl = "";
			
			//根据fileId处理获取附件下载路径
			if(StringUtils.isNotEmpty(fileId)) {
				//获取附件相关数据：根据fileId获取附件相关数据；1、需要判断fileId来源（附件表、网盘）；2、返回文件相关数据
				Map<String,Object> fileParams = new HashMap<String,Object>();
				fileParams.put("fileId", fileId);
				fileParams.put("fileSourceType", fileSourceType);
				fileParams.put("jwtToken", jwtToken);
				FileViewTempDto dto = fileViewTempDtoService.getFileTempDtoInfo(fileParams);
				fileUrl = dto.getFileDownloadUrl();
				fileName = dto.getFileName();
				fileSuffix = dto.getFileExt();
			}
			//校验格式，只支持".doc",".docx",".ppt",".excel",".pdf",".jpg",".png",".ofd",".html"预览
			fileExtLower = fileExtLower.toLowerCase();
			if(!Arrays.asList(allowFileTypesConvert).contains(fileExtLower)){
				result = OperationResult.buildFailureResult("该格式暂不支持");
				return result;
			}
			
			//调用paper服务转版
			Map<String,String> param = new HashMap<String,String>();
			fileName = fileName.replaceAll("“","").replaceAll("”","");
			param.put("fileName", fileName);
			param.put("fileurl", fileUrl);
			if(StringUtils.isNotEmpty(fileExt) && fileExt.equals(".pdf")) {
				LOG.debug("PAPER PDF 转版接口="+servicePath+"/pdf/convert2PDF");
				LOG.debug("PAPER PDF 转版参数="+JSON.toJSONString(param));
				convertUrl = sendPostTranOFD(servicePath+"/pdf/convert2PDF", param, keepAnno);
				LOG.debug("PAPER PDF 转版结果="+convertUrl);
			}else {
				LOG.debug("PAPER 转版接口="+servicePath+"/convert/convert2OFD");
				LOG.debug("PAPER 转版参数="+JSON.toJSONString(param));
				convertUrl = sendPostTranOFD(servicePath+"/convert/convert2OFD", param, keepAnno);
				LOG.debug("PAPER 转版结果="+convertUrl);
			}
			JSONObject urlJson = JSONObject.parseObject(convertUrl);
			if("success".equals(urlJson.get("status"))){
				if(StringUtils.isNotEmpty(fileExt) && fileExt.equals(".pdf")) {
					ofdDoloadUrl = (String) urlJson.get("pdfDoloadUrl");
				}else {
					ofdDoloadUrl = (String) urlJson.get("ofdDoloadUrl");
				}
				result = this.urlOpenStreamWriteSysAttachment(request, ofdDoloadUrl, moduleCode, ofdFileDisplayName, fileExt, fileName, fileSuffix, isUseOldFielName);
			}else{
				result = OperationResult.buildFailureResult("ArteryPaper转化失败");
			}
		} catch (HttpHostConnectException e) {
			LOG.error(e.getMessage(),e);
			result = OperationResult.buildFailureResult("ArteryPaper预览服务器连接失败");
		} catch (ParseException e) {
			LOG.error(e.getMessage(),e);
			result = OperationResult.buildFailureResult("ArteryPaper转化异常");
		} catch (IOException e) {
			LOG.error(e.getMessage(),e);
			result = OperationResult.buildFailureResult("ArteryPaper转化异常");
		} catch (Exception e) {
			LOG.error(e.getMessage(),e);
			result = OperationResult.buildFailureResult("ArteryPaper转化异常");
		}
	
		return result;
	}
	
	/**
	 * 调用将ofd文件落地生成服务文件，并记录附件表
	 * @param request
	 * @param urlStr
	 * @param moduleCode
	 * @param fileName
	 * @param fileExt
	 * @param fileName 
	 * @param fileSuffix 
	 * @param isUseOldFielName 
	 * @return
	 */
	public OperationResult urlOpenStreamWriteSysAttachment(HttpServletRequest request,String urlStr,String moduleCode,
			String ofdFileDisplayName,String fileExt, String fileName, String fileSuffix, String isUseOldFielName){
		OperationResult result = null;
		try {
			if(StringUtils.isNotBlank(urlStr)) {
				urlStr = urlStr.replace("172.16.15.79:9009", "114.255.140.98:52222");
			}
			//paper转版ofd文件访问路径
        	URL url =new URL(urlStr);
        	InputStream is = url.openStream();
        	
        	if(StringUtils.isBlank(fileExt)) {
        		fileExt = ".ofd";
        	}
        	
        	//定义ofd文件名称 
        	String tempFileName = fileName.substring(0,fileName.lastIndexOf(fileSuffix));
        	if(StringUtils.isEmpty(isUseOldFielName) || isUseOldFielName.equals("false")) {
        		tempFileName =  UUID.randomUUID().toString().replace("-", "");
        	}
        	tempFileName = tempFileName + fileExt;
        	
        	if(StringUtils.isNotBlank(ofdFileDisplayName)) {
        		ofdFileDisplayName = ofdFileDisplayName + fileExt;
        	}else {
        		ofdFileDisplayName = tempFileName;
        	}
        	
        	// 导入文件的保存路径
        	AttachUtils attachUtils = new AttachUtils();
        	Attachment attachment = this.attachmentService.findByFileName(tempFileName);
        	String absolutePath = "";
        	if (attachment == null) {
				attachment = new Attachment();
				absolutePath = attachUtils.getUploadAbsolutePath(request,AttachUtils.TEMP_FILEUPLOADPATH_TYPE_EMPTY);
			}else {
				 absolutePath = attachUtils.getUploadAbsolutePath(request,attachment.getFileUploadpathType());
			}
        	
        	String filePath = absolutePath + File.separator + moduleCode + File.separator + "tranofd" + File.separator + tempFileName;
        	
        	File file = new File(filePath);
        	if (!file.getParentFile().exists()) { // 如果文件的目录不存在
        		file.getParentFile().mkdirs(); // 创建目录
			}
        	
        	FileOutputStream fos = new FileOutputStream(file);
        	
        	byte[] buffer = new byte[2048];
        	int len;
        	while ((len = is.read(buffer)) != -1) {
        		fos.write(buffer, 0, len);
        	}
        	
        	if(fos!=null) fos.close();
        	if(is!=null) is.close();
        	
        	
        	attachment.setFileName(tempFileName);
        	if(fileExt.equals(".pdf")) {
        		attachment.setContentType("application/pdf");
			}else if(fileExt.equals(".doc") || fileExt.equals(".docx")){
				attachment.setContentType("application/octet-stream");
			}else if(fileExt.equals(".xls") || fileExt.equals(".xlsx")) {
				attachment.setContentType("application/vnd.ms-excel");
			}else if(fileExt.equals(".ppt") || fileExt.equals(".pptx")) {
				attachment.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
			}else if(fileExt.equals(".wps")) {
				attachment.setContentType("application/kswps");
			}else if(fileExt.equals(".ofd")) {
				attachment.setContentType("application/ofd");
			}
			attachment.setFileDisplayName(ofdFileDisplayName);
			attachment.setFileExt(fileExt);
			attachment.setFileSize(file.length());
			attachment.setRelativePath(moduleCode+"/tranofd");
			attachment.setClientIp(org.ezplatform.util.IPAddrFetcher.getRemoteIpAddress(request));
			attachment
					.setFileSource(Attachment.FileSource.PC);
			attachment.setDelFlag("0");
			String checksum = MD5Utils.hash(tempFileName);
			attachment.setChecksum(checksum);
			attachment.setCleanFlag(0);
			attachment.setPreviewDate(null);
			attachmentService.saveNoTran(attachment);
			result = OperationResult.buildSuccessResult("ArteryPaper转化ofd文件保存成功",attachment);
        }catch(Exception e) {
        	result = OperationResult.buildFailureResult("ArteryPaper转化ofd文件保存失败");
        	LOG.error(e.getMessage(),e);
        }
        return result;
    }
	
	public static String sendViewFileGet(String url){
		JSONObject jsonObject = null;
		try{
			CloseableHttpClient httpClient = HttpClients.createDefault();
			if(url.contains("https:")){
				httpClient = FileViewCommonUtil.getIgnoeSSLClient();
			}
			HttpGet httpGet = new HttpGet(url);
			HttpResponse httpResponse = httpClient.execute(httpGet);
			HttpEntity httpEntity = httpResponse.getEntity();
			if (httpEntity != null) {
				String result = EntityUtils.toString(httpEntity, "UTF-8");
				jsonObject = jsonObject.parseObject(result);
			}
			httpGet.releaseConnection();
		}catch(Exception e){
			LOG.error("paper sendViewFileGet接口异常");
			LOG.error(e.getMessage(),e);
		}

		return jsonObject.toJSONString();
	}

	public OperationResult transformofdqianpi(HttpServletRequest request, String fileId, String oldFileId,
			String moduleCode) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		File file = null;
		LOG.error("paper transformofdqianpi fileId="+fileId);
		LOG.error("paper transformofdqianpi oldFileId="+oldFileId);
		try {
			boolean isExist = false;
			AttachUtils attachUtils = new AttachUtils();
			//签章源文件
			File oldFile = null;
			String oldFilePath = "";
			Attachment oldAttachment = null;
			String absolutePath = "";
			// 1:使用File类创建一个要操作的文件路径
			oldAttachment = attachmentService.findOne(oldFileId);
			if (oldAttachment != null) {
				absolutePath = attachUtils.getUploadAbsolutePath(request,oldAttachment.getFileUploadpathType());
				oldFilePath = absolutePath + File.separator + oldAttachment.getRelativePath() + File.separator + oldAttachment.getFileName();
				oldFile = new File(oldFilePath);
				if (oldFile.exists()) { // 如果文件的目录不存在
					isExist = true;
				}
			}
			LOG.error("paper transformofdqianpi oldFilePath="+oldFilePath);
			if(!isExist) {
				return OperationResult.buildFailureResult("签章源ofd文件"+oldFileId+"文件不存在");
			}
			//初始化isExist = false
			isExist = false;
			//签章源文件
			File newFle = null;
			String newFilePath = "";
			Attachment newAttachment = null;
			String newAbsolutePath = "";
			// 1:使用File类创建一个要操作的文件路径
			newAttachment = attachmentService.getAttachmentById(fileId,true);
			if (newAttachment != null) {
				newAbsolutePath = attachUtils.getUploadAbsolutePath(request,newAttachment.getFileUploadpathType());
				newFilePath = newAbsolutePath + File.separator + newAttachment.getRelativePath() + File.separator + newAttachment.getFileName();
				newFle = new File(newFilePath);
				if (newFle.exists()) { // 如果文件的目录不存在
					isExist = true;
				}
			}
			LOG.error("paper transformofdqianpi newFilePath="+newFilePath);
			if(!isExist) {
				return OperationResult.buildFailureResult("签章新增ofd文件"+fileId+"文件不存在");
			}
			// 临时保存签章数据文件
			long times = new Date().getTime();
			String tempFileName = times + ".txt";
			String tempAbsolutePath = attachUtils.getUploadAbsolutePath(request,AttachUtils.TEMP_FILEUPLOADPATH_TYPE_EMPTY);
			String filePath = tempAbsolutePath + File.separator + moduleCode + File.separator + "qianpi" + File.separator + tempFileName;
			file = new File(filePath);
			if (!file.getParentFile().exists()) { // 如果文件的目录不存在
				file.getParentFile().mkdirs(); // 创建目录
			}
			if(!file.exists()) {
				file.createNewFile();
			}

			String fileExt = oldAttachment.getFileExt();
			//ofd文件 批注处理
			LOG.error("paper transformofdqianpi fileExt="+fileExt);
			if(fileExt.equals(".ofd")){
				IOfdOperationAgent agent = new OfdOperation();
				//从有批注的文件里导出批注内容
				String anno = agent.exportAnnotation(oldFilePath);
//				//导出OFD批注
//				String result = agent.exportAnnotation(oldFilePath);
//				FileUtils.writeByteArrayToFile(new File(filePath), result.getBytes());
//				//导入OFD批注
//				String anno = IOUtils.toString(new FileInputStream(new File(filePath)));
				LOG.error("paper transformofdqianpi anno="+anno);
				if(StringUtils.isNotEmpty(anno)) {
					try {
						JSONObject jsonobj = JSONObject.parseObject(anno);
						String message = jsonobj.getString("message");
						if(StringUtils.isNotEmpty(message) && message.equals("文件中没有注释")) {
							resultMap.put("fileId", fileId);
							resultMap.put("msg", "源文件中没有注释,文件不需处理");
							return OperationResult.buildSuccessResult(resultMap);
						}
					}catch(Exception e) {
						LOG.error(e.getMessage(),e);
					}
				}
				agent.importAnnotation(newFilePath, anno, false);
			}else if(fileExt.equals(".pdf") || fileExt.equals(".PDF")){
				IPdfOperationAgent agent = new PdfOperation();
//				//导出OFD批注
//				String result = agent.exportAnnotation(oldFilePath);
//				FileUtils.writeByteArrayToFile(new File(filePath), result.getBytes());
//				//导入OFD批注
//				String anno = IOUtils.toString(new FileInputStream(new File(filePath)));
				String anno = agent.exportAnnotation(oldFilePath);
				LOG.error("paper transformofdqianpi anno="+anno);
				if(StringUtils.isNotEmpty(anno)) {
					try {
						JSONObject jsonobj = JSONObject.parseObject(anno);
						String message = jsonobj.getString("message");
						if(StringUtils.isNotEmpty(message) && message.equals("文件中没有注释")) {
							resultMap.put("fileId", fileId);
							resultMap.put("msg", "源文件中没有注释,文件不需处理");
							return OperationResult.buildSuccessResult(resultMap);
						}
					}catch(Exception e) {
						LOG.error(e.getMessage(),e);
					}
				}
				agent.importAnnotation(newFilePath, anno, false);
			}

		}catch(Exception e) {
			LOG.error(e.getMessage(),e);
			return OperationResult.buildFailureResult("签章处理失败");
		}finally {
			if(file!=null) {
				file.delete();
			}
		}
		resultMap.put("fileId", fileId);
		resultMap.put("msg", "签章处理成功");
		return OperationResult.buildSuccessResult(resultMap);
	}

	public static void main(String[] args) {
		//带有批注文件
		String oldFilePath = "D:\\ceshiwejian\\paper\\带有批注源文件.ofd";
		//提出批注文件
		String filePath = "D:\\ceshiwejian\\paper\\存放提出批注文件.txt";
		//要合并批注文件
		String newFilePath = "D:\\ceshiwejian\\paper\\要合并批注文件.ofd";
		IOfdOperationAgent agent = new OfdOperation();
		//导出OFD批注
		String result = agent.exportAnnotation(oldFilePath);
		try {
			if(StringUtils.isNotEmpty(result)){
				FileUtils.writeByteArrayToFile(new File(filePath), result.getBytes());
			}
		} catch (IOException e) {
			LOG.error(e.getMessage(),e);
		}
		//导入OFD批注
		String anno;
		try {
			anno = IOUtils.toString(new FileInputStream(new File(filePath)));
			agent.importAnnotation(newFilePath, anno, false);
		} catch (FileNotFoundException e) {
			LOG.error(e.getMessage(),e);
		} catch (IOException e) {
			LOG.error(e.getMessage(),e);
		}
	}

	/**
	 * 获取字段值
	 *
	 * @param urlStr
	 * @param field
	 * @return
	 */
	private static String getFieldValue(String urlStr, String field) {
		String result = "";
		Pattern pXM = Pattern.compile(field + "=([^&]*)");
		Matcher mXM = pXM.matcher(urlStr);
		while (mXM.find()) {
			result += mXM.group(1);
		}
		return result;
	}

	public Map checkFileIsJm(HttpServletRequest request, String fileId, String fileSourceType, String jwtToken, String filePw) {
		Map result = new HashMap();
		try {
			//1、基础参数设置

			//2、相关变量设置
			String convertUrl = "";//预览接口返回结果集：convertUr
			String fileExt = "";//文件后缀名
			String fileExtLower = "";//文件后缀名全部小写
			String fileDownloadUrl = "";
			String fileName = "";

			//3、获取ateryPaper参数设置
			String  servicePath= ConfSettingUtils.getConfSettingValue("sysArteryPaperAppUrl", "0");//获取arteryPaper服务地址(内网)

			//4、获取附件相关数据：根据fileId获取附件相关数据；1、需要判断fileId来源（附件表、网盘）；2、返回文件相关数据
			Map<String,Object> fileParams = new HashMap<String,Object>();
			fileParams.put("fileId", fileId);
			fileParams.put("fileSourceType", fileSourceType);
			fileParams.put("jwtToken", jwtToken);
			FileViewTempDto dto = fileViewTempDtoService.getFileTempDtoInfo(fileParams);
			if (StringUtils.isBlank(dto.getFileId())) {
				String msg = "文件FileId:" + fileId + "不存在";
				result.put("type","1");
				result.put("msg",msg);
				return result;
			}
			fileExt = dto.getFileExt();
			fileExtLower = fileExt.toLowerCase();
			fileDownloadUrl = dto.getFileDownloadUrl();
			fileName = dto.getFileName();

			//5、校验文件是否支持预览及调用ateryPaper预览服务
			//校验格式，只支持".doc",".docx",".ppt",".excel",".pdf",".jpg",".png",".ofd",".html"预览
			if(!Arrays.asList(allowFileTypes).contains(fileExtLower)){
				result.put("type", "1");
				result.put("msg", "文件格式不在校验范围内");
				return result;
			}


			Map<String,String> param = new HashMap<String,String>();
			param.put("fileName", fileName);
			param.put("fileurl", fileDownloadUrl);
			param.put("password", filePw);

			convertUrl = sendViewFileJmPost(servicePath+"/pdf/convert2PDF", param);
			JSONObject urlJson = JSONObject.parseObject(convertUrl);
			String code = urlJson.get("code").toString();
			if (code.equals("408")) {
				String password = param.get("password");
				if(StringUtils.isEmpty(password)){
					result.put("type","2");
					result.put("msg","文件加密预览未给密码");
				}else{
					result.put("type","3");
					result.put("msg","文件加密预览给的不正确");
				}
			}if (code.equals("402")) {
				result.put("type","1");
				result.put("msg","paper转换失败");
			}else if (code.equals("-1")){
				result.put("type","1");
				result.put("msg","paper预览服务错误");
			}else{
				String password = param.get("password");
				if(StringUtils.isEmpty(password)){
					result.put("type","1");
					result.put("msg","文件不加密预览");
				}else{
					result.put("type","4");
					result.put("msg","文件加密预览给的正确");
				}
			}
		} catch (Exception e) {
			LOG.error("paper预览服务错误：", e);
			result.put("type","1");
			result.put("msg","paper预览服务错误");
		}
		return result;
	}

	//推荐用法
	public static String sendViewFileJmPost(String url, Map<String,String> param) throws HttpHostConnectException,IOException,ParseException{
		String result = "";
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		String fullurl = "";
		//请求参数
		for(String key:param.keySet()){
			list.add(new BasicNameValuePair(key, param.get(key)));
		}
		try{
			fullurl = EntityUtils.toString(new UrlEncodedFormEntity(list,Consts.UTF_8));
		}catch (IOException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (ParseException e) {
			result = "{\"result\":-1,\"data\":\"\",\"message\":\"ArteryPaper拼接url参数强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}
		LOG.debug("PAPER URL="+url+"?"+fullurl);
		HttpPost httppost = new HttpPost(url+"?"+fullurl);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		try{
			CloseableHttpResponse response = httpClient.execute(httppost);
			HttpEntity entity = response.getEntity();
			result = EntityUtils.toString(entity);
		}catch (HttpHostConnectException e) {
			result = "{\"code\":-1,\"data\":\"\",\"message\":\"ArteryPaper预览服务器连接失败\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}catch (ParseException e) {
			result = "{\"code\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换强转异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		} catch (IOException e) {
			result = "{\"code\":-1,\"data\":\"\",\"message\":\"ArteryPaper转换IO异常\",\"type\":0}";
			LOG.error(e.getMessage(),e);
		}finally{
			httppost.releaseConnection();
		}
		return result;
	}
}
